<template>
  <!--柱状图-->
  <div
    :style="{width:width,height:height}"
  ></div>
</template>

<script>
  export default {
    name: 'BarCharts',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: ''
      },
      /**
       * @param:
       *    dataLine  --> 折线的数据
       *    dataY  --> Y轴的数据
       * @date 2020/08/23
       * @author ZhuHongWei
       */
      chartData: {
        type: Object,
        default: () => {
        }
      }
    },
    data() {
      return {
        pageSize: 8
      }
    },
    watch: {
      chartData: {
        deep: true,
        handler: function () {
          this.initChart()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart() {
        let that = this
        this.chart = this.$echarts.init(this.$el)
        this.chart.clear()
        let option = {
          color: ['#fccb05','#248ff7', '#8bd46e'],
          legend: {
            data: this.chartData.legendData,
            textStyle: {
              color: '#B4B4B4',
              fontSize: '14px'
            },
            top: '20px',
          },
          dataZoom: [
            {
              type: 'slider',
              show: this.chartData.xName.length > this.pageSize,
              startValue: 0,
              endValue: this.pageSize, // 初始显示index0-30的数据,可根据你的数据量设置
            },
          ],
          tooltip: {},
          xAxis: {
            type: 'category',
            nameTextStyle: {
              color: '#FFFFFF',
              padding: [30, 0, 0, 0]
            },
            axisLabel: {
              textStyle: {
                color: "#FFFFFF",
                fontSize: 14
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisTick: {
              show: true
            },
            data: this.chartData.xName
          },
          yAxis: {
            nameTextStyle: {
              color: '#FFFFFF',
              fontSize: 12,
              padding: [0,0,-20,-80]
            },
            splitLine: {
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
                fontSize: 14
              }
            },
          },
          series: [{
            z: 1,
            name: 'TOP',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: this.chartData.data1,
            symbol : 'diamond',
            symbolOffset: ['-50%', '-50%'],
            symbolSize: [29, 19],
            itemStyle: {
              borderColor: 'rgb(47,255,164)',
              color: 'rgb(47,255,164)'
            },
          },{
            z: 1,
            type: 'bar',
            name: this.chartData.legendData[0],
            barWidth: 30,
            barGap: '-50%',
            data: this.chartData.data1,
            itemStyle: {
              color: {
                type: 'linear',
                x: 0, x2: 1, y: 0, y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgba(29, 245, 160, .7)' },
                  { offset: 0.5, color: 'rgba(29, 245, 160, .7)' },
                  { offset: 0.5, color: 'rgba(29, 245, 160, .3)' },
                  { offset: 1, color: 'rgba(29, 245, 160, .3)' }
                ]
              }
            },
          },{
            z: 2,
            name: 'TOP',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: this.chartData.data2,
            symbol : 'diamond',
            symbolOffset: [0, '-50%'],
            symbolSize: [29, 19],
            itemStyle: {
              borderColor: 'rgb(50,255,238)',
              color: 'rgb(50,255,238)'
            },
          },{
            z: 2,
            type: 'bar',
            name: this.chartData.legendData[1],
            barWidth: 30,
            data: this.chartData.data2,
            itemStyle: {
              color: {
                type: 'linear',
                x: 0, x2: 1, y: 0, y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgba(50, 255, 238, .7)' },
                  { offset: 0.5, color: 'rgba(50, 255, 238, .7)' },
                  { offset: 0.5, color: 'rgba(50, 255, 238, .3)' },
                  { offset: 1, color: 'rgba(50, 255, 238, .3)' }
                ]
              }
            },
          }, {
            z: 3,
            name: 'TOP',
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: this.chartData.data3,
            symbol : 'diamond',
            symbolOffset: ['50%', '-50%'],
            symbolSize: [29, 19],
            itemStyle: {
              borderColor: 'rgb(255,209,26)',
              color: 'rgb(255,209,26)'
            },
          },{
            z: 3,
            type: 'bar',
            name: this.chartData.legendData[2],
            barWidth: 30,
            data: this.chartData.data3,
            itemStyle: {
              color: {
                type: 'linear',
                x: 0, x2: 1, y: 0, y2: 0,
                colorStops: [
                  { offset: 0, color: 'rgba(255, 209, 26, .7)' },
                  { offset: 0.5, color: 'rgba(255, 209, 26, .7)' },
                  { offset: 0.5, color: 'rgba(255, 209, 26, .3)' },
                  { offset: 1, color: 'rgba(255, 209, 26, .3)' }
                ]
              }
            }
          }]
        }
        this.chart.setOption(option)
      }
    }
  }
</script>

<style scoped>
</style>
